package com.mp.ipm2020.mbg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.mp.ipm2020.mbg.model.Control;
import com.mp.ipm2020.mbg.mapper.ControlMapper;
import com.mp.ipm2020.mbg.service.ControlService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author adidasshe
 * @since 2020-05-18
 */
@Service
public class ControlServiceImpl extends ServiceImpl<ControlMapper, Control> implements ControlService {

    @Autowired
    private ControlMapper controlMapper;

    @Override
    public List<Control> list(String keyword, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper<Control> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(keyword)) {
            wrapper.like("operator", keyword)
                    .or()
                    .like("device_id", keyword);
        }
        wrapper.orderByDesc("id");
        return controlMapper.selectList(wrapper);
    }

}
